package com.qidianit.mes.sys.controller;

import com.qidianit.mes.common.Result;
import com.qidianit.mes.pojo.Supplier;
import com.qidianit.mes.sys.service.SupplierService;
import com.qidianit.mes.vo.SupplierPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Package Path: com.qidianit.mes.sys.controller
 * Author: Alhz
 * Description:
 * Date: 2025/9/16 19:33
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 分页+模糊查询
     * @param supplierPageVo
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result selectAllSupplier(SupplierPageVo supplierPageVo, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        return supplierService.findAll(supplierPageVo,pageNum,pageSize);
    }


    /**
     * 根据code获取供应商
     * @param code
     * @return
     */
    @GetMapping("/code/{code}")
    public Result selectSupplierByCode(@PathVariable String code) {
        return supplierService.selectSupplierByCode(code);
    }

    /**
     * 添加供应商
     * @param supplier
     * @return
     */
    @PostMapping("/add")
    public Result addSupplier(@RequestBody Supplier supplier) {
        return supplierService.insertSupplier(supplier);
    }

    /**
     * 更新供应商
     * @param supplier
     * @return
     */
    @PutMapping("/update")
    public Result updateSupplier(@RequestBody Supplier supplier) {
        return supplierService.updateSupplier(supplier);
    }

    /**
     * 删除供应商
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteSupplier(@PathVariable Long id) {
        return supplierService.deleteSupplierByID(id);
    }

    /**
     * 批量删除
     * @param id
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result deleteSupplierByIDs(Long[] id) {
        System.out.println(id);
        return supplierService.batchDeleteSupplier(id);
    }
}
